package com.example.chess.utils;

import android.app.Activity;
import android.widget.Toast;

/**
 * Created by xuyougen.
 */
public class ExitUtils {

    private static long lastPressedMillis;
    private static final int triggerInterval = 2000;

    public static void onBackPressed(Activity activity) {
        long millis = System.currentTimeMillis();
        long difference = millis - lastPressedMillis;
        if (difference < triggerInterval) {
            activity.finish();
            return;
        }
        lastPressedMillis = millis;
        Toast.makeText(activity, "再按一次退出", Toast.LENGTH_SHORT).show();
    }
}
